<?php
/**
 *   获取消息通知
 *   @param
 *   @date 2019/12/8
 *   @author Xiaohui Zeng
 */

namespace app\admin\controller;


use app\model\CmsCommentReply;
use app\model\CmsContent;
use app\util\ReturnCode;

class CmsMsgList extends Base
{
    /**
     *   获取评论回复列表 未审核
     * @param
     * @date 2019/12/8
     * @author Xiaohui Zeng
     */
    public function plList()
    {
        $page = $this->request->get('page', 1);
        $pageSize = $this->request->get('pageSize', 5);
        if (strlen($pageSize)) {
            $limit = $pageSize;
        } else {
            $limit = config('apiAdmin.ADMIN_LIST_DEFAULT');
        }
        $objData = new CmsCommentReply();
        $obj = $objData->where(['hide' => 0, 'ischeck' => 0]);
        $CmsCommentReplyList = $obj->order('createTime ASC')->paginate($limit, false, ['page' => $page])->toArray();
        for( $i=0; $i<count($CmsCommentReplyList['data']); $i++) {
            $wData = CmsContent::get($CmsCommentReplyList['data'][$i]['wid']);
            $CmsCommentReplyList['data'][$i]['wTitle'] = $wData->title; // 获取文章标题
            $CmsCommentReplyList['data'][$i]['wEasytitle'] = $wData->easytitle; // 获取文章简介
        }
        $header = config('apiadmin.CROSS_DOMAIN');
        $ApiAuth = $this->request->header('apiAuth', '');
        $userInfo = cache('Login:' . $ApiAuth);
        $userInfo = json_decode($userInfo, true);
//        $this->debug($userInfo);
        return $this->buildSuccess([
            'list'  => $CmsCommentReplyList['data'],
            'count' => $CmsCommentReplyList['total']
        ], '获取成功');
    }
    /**
     *  评论审核
     * @param
     * @date 2019/12/6
     * @author Xiaohui Zeng
     */
    public function plStatus()
    {
        $id = $this->request->get('id');
        $status = $this->request->get('status');
        $res = CmsCommentReply::update([
            'id'   => $id,
            'hide' => $status,
            'ischeck' => 1
        ]);
        if ($res === false) {
            return $this->buildFailed(ReturnCode::DB_SAVE_ERROR, '操作失败');
        } else {
            return $this->buildSuccess([]);
        }
    }
}